<?php
namespace Siter\Controller;

class PlanController extends Controller {

    public function getPlan() {
        $records = D('Plan')->where(['status' => 1])->select();

        if (!$records) {
            showJson(['s' => false, 'm' => '未找到广告计划数据']);
        }

        $adModel = D('Ad');

        foreach ($records as $k => $v) {
            $expr = [
                'plan_id' => $v['id'],
                'status'  => 1,
            ];
            $records[$k]['ad_num']  = ($d = $adModel->where($expr)->count()) ? $d : 0;
        }

        showJson(['s' => true, 'm' => $records]);
    }

}
